from datetime import datetime
from sqlalchemy import Column, BigInteger, String, Integer, Enum, DateTime, text, Text
from core.database import Base


class CallTasks(Base):
    __tablename__ = 'call_tasks'

    id = Column(BigInteger, primary_key=True, autoincrement=True, comment='主键ID')
    # 任务名称
    task_name = Column(String(100), nullable=False,comment='任务名称')
    #总客户数
    total_count = Column(Integer, nullable=False,comment='总客户数')
    #剩余客户数
    remaining_count = Column(Integer, nullable=False,comment='剩余客户数')
    #任务状态
    status = Column(Enum('pending', 'running', 'completed','cancelled','stopped', name='call_tasks_status_enum'),
                    nullable=False,
                    default='pending',
                    comment='任务状态')
    #创建人
    created_by = Column(String(50), nullable=False,comment='创建人')
    #任务通道
    channel = Column(String(50), nullable=False,comment='任务通道')
    #创建时间
    created_at = Column(DateTime, default=datetime.now, server_default=text('CURRENT_TIMESTAMP'), comment='创建时间')
    #开始时间
    started_at = Column(DateTime, nullable=True,comment='开始时间')
    #完成时间
    completed_at = Column(DateTime, nullable=True,comment='完成时间')
    #备注
    remark = Column(Text, nullable=True,comment='备注')
    #用户id
    user_id = Column(String(36), nullable=False,comment='用户id')

    def to_dict(self):
        # 将模型转换为字典，便于JSON序列化
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}